//
//  ContentView.swift
//  OrganizingWithGrids
//
//  Created by Alfred Jobs on 2022/12/12.
//

import SwiftUI

struct ContentView: View {
    let allColors: [Color] = [
        .pink,
        .red,
        .orange,
        .yellow,
        .green,
        .mint,
        .teal,
        .cyan,
        .blue,
        .indigo,
        .purple,
        .brown,
        .gray
    ]
    @State private var selectedColor: Color = .gray
    
    var body: some View {
        VStack {
            Text("Selected Color")
                .fontWeight(.semibold)
                .foregroundColor(selectedColor)
                .padding(20)
            
            ScrollView {
                LazyVGrid(columns: Array(repeating: GridItem(), count: 3)) {
                    ForEach(allColors, id: \.description) { item in
                        Button {
                            selectedColor = item
                        } label: {
                            Rectangle()
                                .cornerRadius(4)
                                .aspectRatio(1.0, contentMode: .fit)
                                .foregroundColor(item)
                        }
                        .buttonStyle(.plain)
                    }
                }
            }
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
